﻿#region Using

using Microsoft.Xna.Framework.Graphics;

#endregion

namespace XNgine.Util
{
    public static class ColorUtil
    {
        /// <summary>
        /// Blends two colors
        /// </summary>
        /// <param name="c1">First color</param>
        /// <param name="c2">Second color</param>
        /// <param name="ratio">
        /// Blend ratio. 0.5 will give even blend, 1.0 will return 
        /// c1, 0.0 will return c2 and so on.
        /// </param>
        /// <returns>The resulting blended color</returns>
        public static Color blend(Color c1, Color c2, float ratio)
        {
            float invRatio = 1.0f - ratio;

            byte r = (byte) (c1.R*ratio + c2.R*invRatio);
            byte g = (byte) (c1.G*ratio + c2.G*invRatio);
            byte b = (byte) (c1.B*ratio + c2.B*invRatio);

            return new Color(r, g, b);
        }

        /// <summary>
        /// Make an even blend between two colors.
        /// </summary>
        /// <param name="c1">First color to blend.</param>
        /// <param name="c2">Second color to blend.</param>
        /// <returns>Blended color.</returns>
        public static Color blend(Color c1, Color c2)
        {
            return blend(c1, c2, 0.5f);
        }

        /// <summary>
        /// Invert the given color
        /// </summary>
        /// <param name="c">Color to invert</param>
        /// <returns>Inverted color</returns>
        public static Color invert(Color c)
        {
            byte r = (byte) (255 - c.R);
            byte g = (byte) (255 - c.G);
            byte b = (byte) (255 - c.B);
            return new Color(r, g, b);
        }
    }
}